var json2Db=function(tablename){
    
        var _tablename=tablename;
        var _contextPath="/"+window.location.pathname.split("/")[1]+"/rest/";
        return {
                 index:function(request){
                        $.ajax({type: "get",url: _contextPath+_tablename,data:{"type":"index","id":request.id},success:function(json){
                        	request.success(JSON.parse(json));
                        }});
                 },
                 insert:function(request){    
                 		
                        $.ajax({type: "post",url: _contextPath+_tablename,data:{"type":"insert","json":JSON.stringify(request.row)},dataType:"json",success:function(json){
                        	alert(1);
                        	request.success(json);
                        }});
                 },
                 update:function(json){
                        $.ajax({type: "post",url: "/simpleJupiter/rest/mybean",data:{"type":"update","json":json},success:function(){alert("update succuss!");}});
                 },
                 del:function(request){
                        $.ajax({type: "DELETE",url: _contextPath+_tablename+"/"+request.id,success:function(json){
                        	request.success(json);
                        }});
                        
                 }
         }
};

// form to json
$.fn.serializeObject = function()
{
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

